#pragma once
#include "PublicHead.h"

class CNetClient :
	public INetClient
{
public:
	CNetClient( 
		INetNotify* pNetNotify, 
		CLogModule* pLogModule, 
		boost::asio::io_service& io_service_,
		NetIDGenerator& net_id_
		);
	virtual ~CNetClient(void);
	virtual void SetServerAddress( char* pServerAddr, unsigned short nPort );
	virtual void Connect( void );
	virtual void Close( void );
	virtual void SendData( const char* pData, unsigned int unDataLength );
	virtual unsigned __int64 GetClientID( void );

private:
	boost::asio::ip::tcp::resolver::iterator m_resolver;
	INetNotify* m_pNetNotify;
	CLogModule* m_pLogModule;
	boost::asio::io_service& io_service;
	boost::array<char,1024> buffer_;
	NetIDGenerator& m_NetIDGenerator;
	boost::asio::ip::tcp::socket m_ClientSocket;

	unsigned __int64 m_ullClientID;

private:
	void handle_connect(const boost::system::error_code& error);
	void handle_read(const boost::system::error_code& error,const size_t bytes_transferred);
	void handle_write(const boost::system::error_code& error,const size_t bytes_transferred);
	void handle_close( void );
};
